#include "PerspectiveLinearRenderer.h"
void PerspectiveLinearRenderer::scan(unsigned char* p,int len,Interpolant base,Interpolant& diff)
{
    float u,v;
    int u00,u10,u11,u01,
        v00,v10,v11,v01,i00,i10,i11,i01;
    for (;len > 0;len--,p+=3)
    {
        u=base.u*m_texw-0.5f; v=base.v*m_texh-0.5f;
      //  if (u < 0) u+=m_texw; if (v < 0) v+=m_texh;
        u00=((int) u)%m_texw; v00=((int) v)%m_texh; //if (u00 < 0) u00+=m_texw;if (v00 < 0) v00+=m_texh;
        u10=(u00+1)%m_texw;   v10=v00;              //if (u10 < 0) u00+=m_texw;if (v10 < 0) v00+=m_texh;
        u11=(u00+1)%m_texw;   v11=(v00+1)%m_texh;   //if (u11 < 0) u11+=m_texw;if (v11 < 0) v11+=m_texh;
        u01=u00;              v01=(v00+1)%m_texh;   //if (u01 < 0) u01+=m_texw;if (v01 < 0) v01+=m_texh;
        u-=(int) u; v-=(int) v;

        i00=v00*m_texw*4+u00*4; i10=v10*m_texw*4+u10*4;
        i11=v11*m_texw*4+u11*4; i01=v01*m_texw*4+u01*4;
        p[0]=(m_tex[i00  ]*(1-u)+m_tex[i10  ]*u) * (1-v) +
             (m_tex[i01  ]*(1-u)+m_tex[i11  ]*u) * v;
        p[1]=(m_tex[i00+1]*(1-u)+m_tex[i10+1]*u) * (1-v) +
             (m_tex[i01+1]*(1-u)+m_tex[i11+1]*u) * v;
        p[2]=(m_tex[i00+2]*(1-u)+m_tex[i10+2]*u) * (1-v) +
             (m_tex[i01+2]*(1-u)+m_tex[i11+2]*u) * v;
     //   p[1]=m_tex[index+1];
       // p[2]=m_tex[index+2];
        base+=diff;
    }
}
